package com.qianya.system.manage.web.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianya.system.manage.config.RedisUtil;
import com.qianya.system.manage.web.sys.model.SysConfig;
import com.qianya.system.manage.web.sys.service.ISysConfigService;
import com.qianya.system.manage.web.sys.mapper.SysConfigMapper;
import org.springframework.stereotype.Service;
import com.qianya.model.common.CommonResult;
import com.qianya.model.common.ResultCode;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
* <p>
*  系统设置服务实现类
* </p>
*
* @author lhl
* @since 2020-06-11
*/
@Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {

        /**
        *查找 系统设置
        * @author lhl
        * @since 2020-06-11
        */
        @Override
        public CommonResult find() {
            Object obj=RedisUtil.get("sysConfig");
            if (obj==null){
                obj=getById("1");
                RedisUtil.set("sysConfig",obj);
            }
            return CommonResult.success(obj);
        }

        /**
        * 修改 系统设置
        * @author lhl
        * @since 2020-06-11
        */
        @Override
        public CommonResult renewal(SysConfig sysConfig) {
            sysConfig.setSetId("1");
            sysConfig.setSetUpdateTime(new Date());
            boolean b = updateById(sysConfig);
            if (b){
                RedisUtil.set("sysConfig",sysConfig);
                return CommonResult.success();
            }
            return CommonResult.error(ResultCode.ERROR,"操作失败");
        }
}
